import { createStore, applyMiddleware, compose } from 'redux';
import reducer from './reducer.js';

import thunkMiddle from 'redux-thunk'

import createSagaMiddleware from 'redux-saga';

import saga from './saga.js';

const composeEnhancers = window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__({ trace: true}) || compose;

// 应用中间件
// 1. 引入thunkMiddleware中间件
// 2. 创建sagaMiddleware中间件

const sagaMiddleware = createSagaMiddleware();

const storeEnhancer = applyMiddleware(thunkMiddle,sagaMiddleware)
const store = createStore(reducer, composeEnhancers(storeEnhancer));

sagaMiddleware.run(saga);

export default store;
